using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class pylon : Creation
{
    private Rigidbody2D myRigidbody;
    public float healthratio;
    public float CD;
    float CDtime;
    float dietime=90f;
    public GameObject Smartfish,enemy;
    Transform transform;
    findenemy Findenemy;
    public int sonnum;
    void Start()
    {
        myRigidbody = GetComponent<Rigidbody2D>();
        //enemyattack= attackobject.GetComponent<EnemyAttack> ();
        //face = enemyattack.face;
        transform = GetComponent<Transform>();
        CDtime = CD;
        health = healthratio * GameObject.FindWithTag("Player").GetComponent<PlayerBasic>().health;
        Findenemy = GetComponentInChildren<findenemy>();
        attackable = true;
    }
    public override void TakeDamage(float damage)
    {
        if (attackable)
        {
            health -= damage;
                if (health <= 0)
                    Destroy(gameObject);
        }
       
    }

    // Update is called once per frame
    void Update()
    {
        dietime -= Time.deltaTime;
        if (dietime <= 0)
        {
            Destroy(gameObject);
        }
        enemy = Findenemy.enemy;
        if (transform.childCount <sonnum+2)
        {
            if (CDtime > 0)
            {
                CDtime -= Time.deltaTime;
            }
            else
            {
                Instantiate(Smartfish, transform.position,Quaternion.identity,transform);
                CDtime = CD;

            }
        }
        
    }
}
